<template>
  <div class="home">
    <el-container>
      <!-- 侧边栏部分 -->
      <el-aside width="auto">
        <div class="logo"></div>
        <el-menu
          default-active="2"
          :collapse="isCollapse"
          class="el-menu-admin"
          background-color='#f9f9f9'
          @open="handleOpen"
          @close="handleClose"
        >
          <el-submenu index="1">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>用户管理</span>
            </template>
            <el-menu-item index="1-4-1" class="el-icon-star-on">用户列表</el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-container>
        <!-- 头部部分 -->
        <el-header>
          <!-- 点击汉堡按钮，实现折叠展开功能 -->
  <div class="toggle-btn" @click='handopen'>
    <i class="myicon myicon-menu"></i>
  </div>
  <div class="system-title">
    <span>电商后台用户管理</span>
  </div>
  <div class="welcome">
    <span>你好{{username}}</span>
  <el-button type="danger" round @click='loginout' class="outbtn">退出</el-button>
  </div>
        </el-header>
        <!-- 中间主体内容 -->
        <el-main>Main</el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
// @ is an alias to /src

export default {
  created () {
    // 从本地获取用户名
    this.username = localStorage.getItem('username')
  },
  data () {
    return {
      isCollapse: false,
      username: ''
    }
  },
  methods: {
    handleOpen (key, keyPath) {
      console.log(key, keyPath)
    },
    handleClose (key, keyPath) {
      console.log(key, keyPath)
    },
    handopen () {
      this.isCollapse = !this.isCollapse
    },
    loginout () {
      // 退出登录页面，清除token，返回登录页面
      localStorage.clear()
      this.$router.push({ name: 'login' })
    }
  }
}
</script>
<style lang="scss" scoped>
  .home {
    height: 100%;
    .el-menu-admin:not(.el-menu--collapse) {
      width: 200px;
      min-height: 400px;
    }
    .el-container {
      height: 100%;
    }
    .el-aside {
      background-color: #f9f9f9;
    }
    .el-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      background-color: #409eff;
    }
    .logo {
      height: 60px;
      background: url(../assets/logo.png);
      background-size: cover;
      background-color: white;
    }
    .toggle-btn {
      padding: 0 15px;
      margin-left: -20px;
      font-size: 36px;
      color: white;
      cursor: pointer;
      line-height: 60px;
      &:hover {
        background-color: #4292cf;
      }
    }
    .system-title {
      font-size: 28px;
      color: white;
    }
    .welcome {
      color: white;
    }
    .outbtn{
      background-color: rgb(233, 67, 67);
    }
  }
</style>
